using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;
public partial class Admin_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            load_data();
        }
    }
    private void load_data()
    {
        PagerV2_8_1.PageSize = 5;
        int Total = 0;
        Criteria cri = new Criteria();
        if (txt_TenTT.Text != "")
        {
            cri.add(Condition.AND, tbTrangThaiSPColumns.TenTrangThai.ToString(), Condition.EQUAL, txt_TenTT.Text);
        }
        tbTrangThaiSPCollection ttspColection = tbTrangThaiSPBUS.Get(cri.Criter, PagerV2_8_1.CurrentIndex,
                                              PagerV2_8_1.PageSize, tbTrangThaiSPColumns.IdTrangThaiSP.ToString(),
                                              OrderDirection.ASC.ToString(), out Total);
        Repeater1.DataSource = ttspColection;
        Repeater1.DataBind();
        PagerV2_8_1.ItemCount = Total;
        if (Total <= PagerV2_8_1.PageSize)
        {
            PagerV2_8_1.Visible = false;
        }
        
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {

            HyperLink hyp_TenTT = (HyperLink)e.Item.FindControl("hyp_TenTT");
            Literal lit_MaTT = (Literal)e.Item.FindControl("lit_MaTT");
            HyperLink hyp_Edit = (HyperLink)e.Item.FindControl("hyp_Edit");
            HiddenField hf_id = (HiddenField)e.Item.FindControl("hf_id");
            tbTrangThaiSP ttsp = (tbTrangThaiSP)e.Item.DataItem;
            lit_MaTT.Text = ttsp.IdTrangThaiSP .ToString();
            hyp_TenTT.NavigateUrl = "LoaiSPDetail.aspx?id=" + ttsp.IdTrangThaiSP.ToString();
            hyp_Edit.NavigateUrl = "TrangThaiSPEdit.aspx?id=" + ttsp.IdTrangThaiSP.ToString();
            hf_id.Value = ttsp.IdTrangThaiSP.ToString();
            hyp_TenTT.Text = ttsp.TenTrangThai;
        }
    }
    protected void btn_Search_Click(object sender, EventArgs e)
    {
        load_data();
    }
    protected void lbt_Delete_Click(object sender, EventArgs e)
    {
        foreach (RepeaterItem item in this.Repeater1.Items)
        {
            CheckBox chk = (CheckBox)item.FindControl("cb_xoa");
            if (chk.Checked == true)
            {
                HiddenField hf_id = (HiddenField)item.FindControl("hf_id");
                tbTrangThaiSPBUS.Delete_TTSP(int.Parse(hf_id.Value));
            }
        }
        load_data();
    }
    protected void pager_Command(object sender, CommandEventArgs e)
    {
        PagerV2_8_1 .CurrentIndex = int.Parse (e.CommandArgument.ToString ());
        load_data();
    }
}
